﻿$(function () {
    var currentPage = 0;
    var orderType = getQueryString("orderType");
    var orderTotlaPage = $("#orderTotlaPage").html();
    //alert(orderTotlaPage);

    //选中订单类型
    if (orderType == 3) {
        $("#orderStatus option[value='" + orderType + "']").attr("selected", true);
        $("#labOrderType").html('已取消的订单');
    }
    else {
        $("#orderType option[value='" + orderType + "']").attr("selected", true);
        var $selectOrderTypeText = $('#orderType option:selected').text();
        $("#labOrderType").html($selectOrderTypeText);
    }

    //订单类型改变
    $("#orderType").change(function () {
        var $selectOrderType = $('#orderType option:selected').val();
        window.location.href = 'OrderList?orderType=' + $selectOrderType;
    });

    //订单状态改变
    $("#orderStatus").change(function () {
        var $selectOrderStatus = $('#orderStatus option:selected').val();
        window.location.href = 'OrderList?orderType=' + $selectOrderStatus;
    });

    //得到query string
    function getQueryString(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
    }

    //取消订单
    function cancelOrder() {

    }
          
    contrlPageNumberDisplay();
    /*-------------分页---------------*/
           
    //控制页码是否显示
    function contrlPageNumberDisplay() {
        $('#currentPage').html(currentPage + 1);
        //当处于首页的时候,'上一页'隐藏
        if (currentPage == 0) {
            $('#previousPage').hide();
        }
        else {
            $('#previousPage').show();
        }
        //当处于末页的时候,'下一页'隐藏
        if (currentPage == (orderTotlaPage - 1)) {
            $('#nextPage').hide();
        }
        else {
            $('#nextPage').show();
        }
    }

            
    //首页
    var $fristPage = $("#fristPage");
    $fristPage.click(function (e) {
        $.get("OrderListByAjaxRequest?orderType=" + orderType + "&pageIndex=0", function (data) {
            currentPage = 0;
            $('#result').empty();
            $('#result').html(data);//替换成新的数据
            contrlPageNumberDisplay();
        });
    });

    //上一页
    var $previousPage = $("#previousPage");
    $previousPage.click(function (e) {
        $.get("OrderListByAjaxRequest?orderType=" + orderType + "&pageIndex=" + (currentPage - 1), function (data) {
            currentPage = currentPage - 1;
            $('#result').empty();
            $('#result').html(data);//替换成新的数据
            contrlPageNumberDisplay();
        });
    });

    //下一页
    var $nextPage = $("#nextPage");
    $nextPage.click(function (e) {
        $.get("OrderListByAjaxRequest?orderType=" + orderType + "&pageIndex=" + (currentPage + 1), function (data) {
            currentPage = currentPage + 1;
            $('#result').empty();
            $('#result').html(data);//替换成新的数据
            contrlPageNumberDisplay();
        });
    });

    //末页
    var $lastPage = $("#lastPage");
    $lastPage.click(function (e) {
        $.get("OrderListByAjaxRequest?orderType=" + orderType + "&pageIndex=" + (orderTotlaPage - 1), function (data) {
            currentPage = orderTotlaPage - 1;
            $('#result').empty();
            $('#result').html(data);//替换成新的数据
            contrlPageNumberDisplay();
        });
    });
});